package com.zmcc.clients;

import com.zmcc.entity.VoiceNotifyTemplate;
import com.zmcc.entity.common.CommonRequest;
import com.zmcc.entity.common.CommonResponse;
import com.zmcc.sender.DefaultSyncClient;
import com.zmcc.sender.ISyncClient;
import com.zmcc.service.IVoiceNotifyRequest;
import com.zmcc.service.impl.VoiceNotifyRequestCommercial;
import com.zmcc.utils.WrapperUtils;

public class VoiceNotifyClient {
    private final ISyncClient syncClient;

    private final IVoiceNotifyRequest requestWrapper;

    private final String appkey;

    private final String appsecret;

    private final String mode;

    public VoiceNotifyClient(Builder builder) {
        this.appkey = builder.appkey;
        this.appsecret = builder.appsecret;
        this.mode = builder.mode;
        this.syncClient = DefaultSyncClient.getInstance();
        this.requestWrapper = VoiceNotifyRequestCommercial.getInstance();
    }

    public static class Builder {
        private String appkey;
        private String appsecret;
        private String mode;

        public Builder() {

        }

        public Builder appkey(String appkey) {
            this.appkey = appkey;
            return this;
        }

        public Builder appsecret(String appsecret) {
            this.appsecret = appsecret;
            return this;
        }

        public Builder mode(String mode) {
            this.mode = mode;
            return this;
        }

        public VoiceNotifyClient build() {
            return new VoiceNotifyClient(this);
        }
    }

    public void sendVoiceNotify(VoiceNotifyTemplate template) {
        CommonRequest request = this.requestWrapper.getSendVoiceNotifyRequest(template);
        request.setHeaderParams(WrapperUtils.authHeaderToMap(WrapperUtils.authHeader(appkey, appsecret)));
        CommonResponse response = this.syncClient.fetch(request);
    }
}
